package kr.saeildamil.androidStudy_second.fragment.cp;

import kr.saeildamil.androidStudy_second.R;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class ProductList extends Activity {
	ProductDBHelper mHelper;
	Cursor cursor;

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch26_productlist);

		mHelper = new ProductDBHelper(this, "Product.db", null, 1);
		SQLiteDatabase db = mHelper.getWritableDatabase();

		String sql = "select * from product";
		cursor = db.rawQuery(sql, null);

		startManagingCursor(cursor);

		SimpleCursorAdapter adapter = null;
		adapter = new SimpleCursorAdapter(this,
				android.R.layout.simple_list_item_2, cursor, new String[] {
						"name", "price" }, new int[] { android.R.id.text1,
						android.R.id.text2 });
		ListView list = (ListView) findViewById(R.id.ch26_productlist_view);
		list.setAdapter(adapter);
	}
}
